<template>
  <div>
    <el-card class="login-form-layout">
      <el-form
        autocomplete="on"
        :model="loginForm"
        ref="loginForm"
        label-position="left"
      >
        <h2 class="login-title color-main">mall-admin-web</h2>
        <el-form-item prop="username">
          <el-input
            name="username"
            type="text"
            v-model="loginForm.username"
            autocomplete="on"
            placeholder="请输入用户名"
          >
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            name="password"
            v-model="loginForm.password"
            autocomplete="on"
            placeholder="请输入密码"
          >
          </el-input>
        </el-form-item>
        <el-form-item style="margin-bottom: 60px">
          <el-button
            style="width: 100%"
            type="primary"
            @click.native.prevent="handleLogin"
          >登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import {login} from '@/api/login'
export default {
  name: 'login',
  data () {
    return {
      loginForm: {
        username: 'admin',
        password: '123456'
      }
    }
  },
  methods: {
    handleLogin () {
      login(this.loginForm).then(res => {
        console.log(res)
        if (res.data.status === 1001) {
          console.log(111)
          this.$router.push({
            path: '/success',
            query: { data: res.data.data }
          })
        } else {
          this.$router.push({
            path: '/error',
            query: { message: res.data.message }
          })
        }
      })
      // this.$refs.loginForm.validate(valid => {
      //   if (valid) {
      //     this.loading = true;
      //     this.$store
      //       .dispatch("Login", this.loginForm)
      //       .then(response => {
      //         this.loading = false;
      //         let code = response.data.code;
      //         if (code == 200) {
      //           this.$router.push({
      //             path: "/success",
      //             query: { data: response.data.data }
      //           });
      //         } else {
      //           this.$router.push({
      //             path: "/error",
      //             query: { message: response.data.message }
      //           });
      //         }
      //       })
      //       .catch(() => {
      //         this.loading = false;
      //       });
      //   } else {
      //     // eslint-disable-next-line no-console
      //     console.log("参数验证不合法！");
      //     return false;
      //   }
      // });
    }
  }
}
</script>

<style scoped>
.login-form-layout {
  position: absolute;
  left: 0;
  right: 0;
  width: 360px;
  margin: 140px auto;
  border-top: 10px solid #409eff;
}

.login-title {
  text-align: center;
}

.login-center-layout {
  background: #409eff;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  margin-top: 200px;
}
</style>
